<?php
//后台首页控制器
namespace App\Http\Controllers\Admin;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Validator;
use App\Http\Requests;
use App\Http\Model\Admin_user;
use Illuminate\Support\Facades\Input;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Crypt;


class IndexController extends Controller
{


    //加载后台网站首页
    public function index()
    {
        
        return view("admin.index");
    }


    //修改密码
    public function pass()
    {

        return view('admin.pass');
    }
    //处理修改密码
    public function dopass()
    {
         $input = Input::except('_token');
         $input['password']=Crypt::encrypt($input['password']);
         $input = Admin_user::create($input);
        
         //原始密码必须输入，长度在6-18位
         //新密码必须跟确认密码一致
        $rule =[
            'password_o'=>'required|between:3,18',
            'password'=>'confirmed|between:6,20'
        ];
        $mess=[
            'password_o.required'=>'必须输入原始密码',
            'password_o.between'=>'原始密码必须在3-18位之间',
            'password.confirmed'=>'新密码跟确认密码不一致',
            'password.between'=>'新密码必须在6-20位之间',
        ];

//        Validator::make('要验证的数据','验证规则','提示信息的格式')
        

        $validator = Validator::make($input,$rule,$mess);

        if ($validator->fails()) {
            return back()
                ->withErrors($validator)
                ->withInput();

//            withInput()返回给模板的内容通过old('表单控件名称')接受
//
//            模板中，用session('msg')接受
//            return back()->with('msg','状态信息');
//            模板中，$data来接受data变量
//            return view('admin.user')->with('data','用户信息');

        }else{
            return back()
                ->with('errors','修改成功');
        }

        

    }

}
